package es.ats.codington.festival.daos;

import java.util.ArrayList;
import java.util.Properties;

import org.springframework.jdbc.core.JdbcTemplate;

import es.ats.codington.festival.domain.Places;
import es.ats.codington.festival.interfaces.daos.IPlaceDAOImp;
import es.ats.codington.festival.mappers.PlaceMapper;




public class PlaceDAOImp implements IPlaceDAOImp{
	
	
	private JdbcTemplate jdbcTemplateObject;
	private Properties queryProperties;
	
	public PlaceDAOImp(JdbcTemplate jdbcTemplateObject,Properties queryProperties){
		this.jdbcTemplateObject = jdbcTemplateObject;
	    this.queryProperties = queryProperties;
	}
	
	public Places getPlaceById(int placeId){
		Places place;
		place = (Places) jdbcTemplateObject.queryForObject(queryProperties.getProperty("getplacebyid"), new Object[]{placeId}, new PlaceMapper());
		
		return place;

	}
	
	public int insertPlace(Places places){
		int aRows=0;
		aRows = jdbcTemplateObject.update(queryProperties.getProperty("insertplace"), places.getPlaceName(), places.getPlaceType(), places.getCapacity(), places.getPlaceDescription(), places.getZone());
		
		return aRows;
	}
	
	
	public int deletePlace(int placeId){
		int aRows = 0;
		aRows = jdbcTemplateObject.update(queryProperties.getProperty("deleteplace"),placeId);

		return aRows;
	}
	
	public int updatePlace(Places uPlace){
		int aRows = 0;
		aRows = jdbcTemplateObject.update(queryProperties.getProperty("updateplace"), uPlace.getPlaceName(), uPlace.getCapacity(), uPlace.getPlaceDescription(), uPlace.getZone(), uPlace.getPlaceId());

		return aRows;
	}
	
	public ArrayList<Places> getAllPlaces(){
		ArrayList<Places> listPlaces = new ArrayList<Places>();
		listPlaces = (ArrayList<Places>) jdbcTemplateObject.query(queryProperties.getProperty("getplacelist"), new PlaceMapper());
		
		return listPlaces;
	}
}
